//
//  RealNameCertifyView.m
//  bitcoin
//
//  Created by caiyajun on 2018/5/11.
//  Copyright © 2018年 比特币. All rights reserved.
//

#import "RealNameCertifyView.h"


@interface RealNameCertifyView()
@property (weak, nonatomic) IBOutlet UIView *closeView;

@property (weak, nonatomic) IBOutlet UIView *nameView;
@property (weak, nonatomic) IBOutlet UIView *numberView;
@property (weak, nonatomic) IBOutlet UIView *contentView;

@property (weak, nonatomic) IBOutlet UIButton *sureButton;

- (IBAction)submitAction:(UIButton *)sender;

@end
@implementation RealNameCertifyView

+ (instancetype)xib
{
    return [[NSBundle mainBundle] loadNibNamed:@"RealNameCertifyView" owner:self options:nil][0];
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    view.backgroundColor = [UIColor blackColor];
    view.alpha = 0.75;
    [self addSubview:view];
    self.alpha = 1;
    self.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    [self addSubview:self.closeView];
    [self addSubview:self.contentView];
    
    
    self.countryView.layer.borderColor = RGBColor(69, 72, 90).CGColor;
    self.countryView.layer.borderWidth = 1.0f;
    
    self.nameView.layer.borderColor = RGBColor(69, 72, 90).CGColor;
    self.nameView.layer.borderWidth = 1.0f;
    
    self.numberView.layer.borderColor = RGBColor(69, 72, 90).CGColor;
    self.numberView.layer.borderWidth = 1.0f;
    
    [_nameTF setValue:[UIColor colorWithHexString:@"#606378"] forKeyPath:@"_placeholderLabel.textColor"];
    [_numberTF setValue:[UIColor colorWithHexString:@"#606378"] forKeyPath:@"_placeholderLabel.textColor"];
    //增加监听，当键盘出现或改变时收出消息
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    //增加监听，当键退出时收出消息
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    
    UITapGestureRecognizer *tapGesturRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
    
    [self.closeView addGestureRecognizer:tapGesturRecognizer];

    
    self.countryView.placeholder = @"国家或地区";
    self.countryView.textColor = [UIColor colorWithHexString:@"#999999"];
    self.countryView.font = [UIFont boldSystemFontOfSize:14];
//    self.countryView.listArray = self.countryArray;
    
    
    [self.sureButton setBackgroundImage:[UIImage imageWithColor:RGBColor(86, 54, 157)] forState:(UIControlStateHighlighted)];
    
}



//当键盘出现或改变时调用
- (void)keyboardWillShow:(NSNotification *)aNotification {
    //获取键盘的高度
    NSDictionary *userInfo = [aNotification userInfo];
    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    int height = keyboardRect.size.height;
    self.contentView.frame=CGRectMake(0, ScreenHeight-270-height, ScreenWidth, 461);

    
}
- (void)keyboardWillHide:(NSNotification *)aNotification {

    
    self.contentView.frame=CGRectMake(0, ScreenHeight-461, ScreenWidth, 461);

    
}



- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self endEditing:YES];
}





- (IBAction)submitAction:(UIButton *)sender {
    if (self.submitActionBlock) {
        self.submitActionBlock(sender.tag);
    }
    
    
    
    
}
- (void)tapAction{
    [self removeFromSuperview];
}

- (void)dealloc{
    //取消监听
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
